<?php

namespace App\Admin\Controllers;

use App\Models\Community;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class CommunityController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Community(), function (Grid $grid) {
            $grid->column('id');
            $grid->column('community_name');
            $grid->column('region_id');
            $grid->column('address');
            $grid->column('built_year');
            $grid->column('property_company');
            $grid->column('property_fee');
            $grid->column('building_count');
            $grid->column('household_count');
            $grid->column('plot_ratio');
            $grid->column('greening_rate');
            $grid->column('parking_count');
            $grid->column('updated_at');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('community_name');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Community(), function (Show $show) {
            $show->field('id');
            $show->field('community_name');
            $show->field('region_id');
            $show->field('address');
            $show->field('built_year');
            $show->field('property_company');
            $show->field('property_fee');
            $show->field('building_count');
            $show->field('household_count');
            $show->field('plot_ratio');
            $show->field('greening_rate');
            $show->field('parking_count');
            $show->field('facilities');
            $show->field('description');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Community(), function (Form $form) {
            $form->display('id');
            $form->text('community_name')->width(4)->required();
            //$form->select('region_id');
            $form->year('built_year')->width(4)->required();
            $form->text('property_company')->width(4);
            $form->text('property_fee')->width(4);
            $form->number('building_count')->min(0)->default(0)->required();
            $form->number('household_count')->min(0)->default(0)->required();
            $form->rate('plot_ratio')->width(4)->default(0);
            $form->rate('greening_rate')->width(4)->default(0);
            $form->number('parking_count')->min(0)->default(0);
            $form->text('address')->required();
            $form->textarea('facilities');
            $form->textarea('description');
        });
    }
}
